﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using FrameWork.web.Code;
using FrameWork.Entity;
using FrameWork.Components;

namespace FrameWork.web.Module.ITMS.Service.StatReport
{
    public partial class ServiceStat : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //绑定报修人部门
                sys_Group sg = new sys_Group();
                its_GroupCs sgCs = new its_GroupCs();
                DataTable dtGroup = sgCs.Group_SelectInfo(sg);
                DataRow drGroup = dtGroup.NewRow();
                drGroup["G_CName"] = "不限";
                drGroup["GroupID"] = "-1";
                dtGroup.Rows.InsertAt( drGroup,0);
                this.Dept_drpGroup.DataTextField = "G_CName";
                this.Dept_drpGroup.DataValueField = "GroupID";
                this.Dept_drpGroup.DataSource = dtGroup;
                this.Dept_drpGroup.DataBind();
            }
        }

        private void Dept_Bind()
        {
            try
            {
                int drpStatue = int.Parse(lblStatue.Text.Trim());
                string dtbeg = lblTimeBegin.Text.Trim() + " 00:00:01";
                string dtend = lblTimeEnd.Text.Trim() + " 23:59:59";
                its_ServiceStatCs isCs = new its_ServiceStatCs();
                ArrayList arr = isCs.its_StatByDeputy(drpStatue, dtbeg.Trim(), dtend.Trim(), this.PagerRept.CurrentPageIndex, this.PagerRept.PageSize);
                this.GvRepDept.DataSource = arr[1] as DataTable;
                this.GvRepDept.DataBind();
                this.PagerRept.RecordCount = (int)arr[0];
            }
            catch(Exception ex)
            {
                FileTxtLogs.WriteLog("报修部门统计出错,错误原因:" + ex.Message);
                string msg = "报修部门统计出错,错误原因:" + ex.Message.Replace("\n", "\\n");
                ClientScript.RegisterStartupScript(this.GetType(), "Wrong", "<script>alert('" + msg + "');</script>");
            }
        }

       
        //报修部门统计
        protected void Button1_Click(object sender, EventArgs e)
        {
            lblStatue.Text = (string)Common.sink(this.A_Cat.UniqueID, MethodType.Post, 20, 0, DataType.Str);
            DateTime dtBegin = (DateTime)Common.sink(this.S_E_DateTime.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            lblTimeBegin.Text = dtBegin.ToString("yyyy-MM-dd");
            
            DateTime dtEnd = (DateTime)Common.sink(this.E_E_DateTime.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            lblTimeEnd.Text = dtEnd.ToString("yyyy-MM-dd");
            PagerRept.CurrentPageIndex = 0;
            Dept_Bind();
        }

        protected void PagerPSN_PageChanged(object sender, EventArgs e)
        {
            Repsn_Bind();
        }

        private void Repsn_Bind()
        {
            try
            {
                string RepDeptNo = this.labRepsnGroup.Text;
                string Statue = labRepsnType.Text.Trim();

                string dtbeg = lab_RePSNBeginTime.Text.Trim() + " 00:00:01";
                string dtend = lab_RePSNEndTime.Text.Trim() + " 23:59:59";
                its_ServiceStatCs isCs = new its_ServiceStatCs();
                ArrayList arr = isCs.its_StatByRePSN(RepDeptNo, Statue, dtbeg.Trim(), dtend.Trim(), this.PagerPSN.CurrentPageIndex, this.PagerPSN.PageSize);
                this.GvRepPSN.DataSource = arr[1] as DataTable;
                this.GvRepPSN.DataBind();
                this.PagerPSN.RecordCount = (int)arr[0];
            }
            catch (Exception ex)
            {
                FileTxtLogs.WriteLog("报修人员统计出错,错误原因:" + ex.Message);
                string msg = "报修人员统计出错,错误原因:" + ex.Message.Replace("\n", "\\n");
                ClientScript.RegisterStartupScript(this.GetType(), "Wrong", "<script>alert('" + msg + "');</script>");
            }
        }

        protected void btnRepsn_Click(object sender, EventArgs e)
        {
            labRepsnType.Text = (string)Common.sink(this.ddlRepsnType.UniqueID, MethodType.Post, 20, 0, DataType.Str);
            labRepsnGroup.Text = (string)Common.sink(this.Dept_drpGroup.UniqueID, MethodType.Post, 20, 0, DataType.Str);
            DateTime dtBegin = (DateTime)Common.sink(this.txt_RePSNBeginTime.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            lab_RePSNBeginTime.Text = dtBegin.ToString("yyyy-MM-dd");

            DateTime dtEnd = (DateTime)Common.sink(this.txt_RePSNEndTime.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            lab_RePSNEndTime.Text = dtEnd.ToString("yyyy-MM-dd");
            PagerPSN.CurrentPageIndex = 0;
            Repsn_Bind();
        }

        protected void PagerDocSolvPSN_PageChanged(object sender, EventArgs e)
        {
            ReSolvPSN_Bind();
        }

        protected void PagerRept_PageChanged(object sender, EventArgs e)
        {
            Dept_Bind();
        }

        private void ReSolvPSN_Bind()
        {
            try
            {


                string dtbeg = lab_ReSolvPSNBeginTime.Text.Trim() + " 00:00:01";
                string dtend = lab_ReSolvPSNEndTime.Text.Trim() + " 23:59:59";
                its_ServiceStatCs isCs = new its_ServiceStatCs();
                ArrayList arr = isCs.its_StatBySolvPSN(dtbeg.Trim(), dtend.Trim(), this.PagerDocSolvPSN.CurrentPageIndex, this.PagerDocSolvPSN.PageSize);
                this.gvDocSolvPSN.DataSource = arr[1] as DataTable;
                this.gvDocSolvPSN.DataBind();
                this.PagerDocSolvPSN.RecordCount = (int)arr[0];
            }
            catch (Exception ex)
            {
                FileTxtLogs.WriteLog("维修人员统计出错,错误原因:" + ex.Message);
                string msg = "维修人员统计出错,错误原因:" + ex.Message.Replace("\n", "\\n");
                ClientScript.RegisterStartupScript(this.GetType(), "Wrong", "<script>alert('" + msg + "');</script>");
            }
        }

        protected void btn_ReSolvPSN_Click(object sender, EventArgs e)
        {
            DateTime dtBegin = (DateTime)Common.sink(this.txt_ReSolvPSNBeginTime.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            lab_ReSolvPSNBeginTime.Text = dtBegin.ToString("yyyy-MM-dd");

            DateTime dtEnd = (DateTime)Common.sink(this.txt_ReSolvPSNEndTime.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            lab_ReSolvPSNEndTime.Text = dtEnd.ToString("yyyy-MM-dd");
            this.PagerDocSolvPSN.CurrentPageIndex = 0;
            ReSolvPSN_Bind();

        }

        protected void Troub_txtBeginTime_TextChanged(object sender, EventArgs e)
        {

        }

        protected void Troub_btnRep_Click(object sender, EventArgs e)
        {
            DateTime dtBegin = (DateTime)Common.sink(this.Troub_txtBeginTime.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            Troub_labBeginTime.Text = dtBegin.ToString("yyyy-MM-dd");

            DateTime dtEnd = (DateTime)Common.sink(this.Troub_txtEndTime.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            Troub_labEndTime.Text= dtEnd.ToString("yyyy-MM-dd");
            Troub_labState.Text = this.Troub_drpState.SelectedValue;
            this.PagerStatByTroub.CurrentPageIndex = 0;
            Troub_Bind();
        }
        /// <summary>
        /// 故障分类绑定
        /// </summary>
        private void Troub_Bind()
        {
            try
            {
                string dtbeg = Troub_labBeginTime.Text.Trim() + " 00:00:01";
                string dtend = Troub_labEndTime.Text.Trim() + " 23:59:59";
                its_ServiceStatCs isCs = new its_ServiceStatCs();
                ArrayList arr = isCs.its_StatByTroub(Troub_labState.Text, dtbeg.Trim(), dtend.Trim(), this.PagerStatByTroub.CurrentPageIndex, this.PagerStatByTroub.PageSize);
                this.gvStatByTroub.DataSource = arr[1] as DataTable;
                this.gvStatByTroub.DataBind();
                this.PagerStatByTroub.RecordCount = (int)arr[0];
            }
            catch (Exception ex)
            {
                FileTxtLogs.WriteLog("故障分类统计出错,错误原因:" + ex.Message);
                string msg = "故障分类统计出错,错误原因:" + ex.Message.Replace("\n", "\\n");
                ClientScript.RegisterStartupScript(this.GetType(), "Wrong", "<script>alert('" + msg + "');</script>");
            }
        }

        protected void PagerStatByTroub_PageChanged(object sender, EventArgs e)
        {
            Troub_Bind();
        }

        protected void ProbType_btnRep_Click(object sender, EventArgs e)
        {
            DateTime dtBegin = (DateTime)Common.sink(this.ProbType_txtBeginTime.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            ProbType_labBeginTime.Text = dtBegin.ToString("yyyy-MM-dd");

            DateTime dtEnd = (DateTime)Common.sink(this.ProbType_txtEndTime.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            ProbType_labEndTime.Text = dtEnd.ToString("yyyy-MM-dd");
            ProbType_labState.Text = this.ProbType_drpState.SelectedValue;
            this.PagerStatByProbType.CurrentPageIndex = 0;
            ProbType_Bind();
        }
        /// <summary>
        /// 问题分类绑定
        /// </summary>
        private void ProbType_Bind()
        {
            try
            {
                string dtbeg = ProbType_labBeginTime.Text.Trim() + " 00:00:01";
                string dtend = ProbType_labEndTime.Text.Trim() + " 23:59:59";
                its_ServiceStatCs isCs = new its_ServiceStatCs();
                ArrayList arr = isCs.its_StatByProbType(ProbType_labState.Text, dtbeg.Trim(), dtend.Trim(), this.PagerStatByProbType.CurrentPageIndex, this.PagerStatByProbType.PageSize);
                this.gvStatByProbType.DataSource = arr[1] as DataTable;
                this.gvStatByProbType.DataBind();
                this.PagerStatByProbType.RecordCount = (int)arr[0];
            }
            catch (Exception ex)
            {
                FileTxtLogs.WriteLog("故障分类统计出错,错误原因:" + ex.Message);
                string msg = "故障分类统计出错,错误原因:" + ex.Message.Replace("\n", "\\n");
                ClientScript.RegisterStartupScript(this.GetType(), "Wrong", "<script>alert('" + msg + "');</script>");
            }
        }

        protected void PagerStatByProbType_PageChanged(object sender, EventArgs e)
        {
            ProbType_Bind();
        }
       
    }
}
